﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="MsgCenter.Web.Pages.Module.Index"
    MasterPageFile="~/Master.Master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="headerContent" runat="server">
    <link rel="stylesheet" media="screen" type="text/css" href="<%=ResolveClientUrl("~/JavaScript/Tree/tree.css") %>" />
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/Tree/tree.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/jqGrid/i18n/grid.locale-cn.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/jqGrid/jquery.jqGrid.min.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/jqGrid/myJqgrid.js") %>"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="mainContent" runat="server">
    <div class="page-content">
        <div class="row">
            <div class="col-xs-12">
                <div class="row">
                    <div class="col-sm-6">
                        <div class="widget-box">
                            <div class="widget-header header-color-blue2">
                                <h4 class="lighter smaller">
                                    模块列表</h4>
                            </div>
                            <div class="widget-body" style="height: 445px">
                                <div class="widget-main padding-8">
                                    <div id="tree" style="height: 440px; overflow-x: no; overflow-y: auto;">
                                        <img src="../../Images/tree/loading.gif" />
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <div class="widget-box">
                            <div class="widget-header header-color-green2">
                                <h4 class="lighter smaller">
                                    操作功能</h4>
                            </div>
                            <div class="widget-body">
                                <div class="widget-main padding-8">
                                    <span>所选名称:</span><input type="text" id="txtDeptName" readonly="readonly" />
                                </div>
                                <div class="widget-main padding-8" id="divAuth">
                                    <%-- <a href="#" onclick="ManagerTreeNode('Add');" class="btn btn-app btn-purple btn-xs">
                                        <i class="icon-cog bigger-160"></i>新增</a>&nbsp;<a href="#" onclick="ManagerTreeNode('Edit');"
                                            class="btn btn-app btn-primary btn-xs"><i class="icon-edit bigger-160"></i>编辑
                                    </a>&nbsp;<a href="#" onclick="ManagerTreeNode('Delete');" class="btn btn-app btn-danger btn-xs">
                                        <i class="icon-trash bigger-160"></i>删除 </a>&nbsp;<a href="#" onclick="ManagerTreeNode('Sort');"
                                            class="btn btn-app btn-pink btn-xs"><i class="icon-share-alt bigger-160"></i>排序
                                        </a>&nbsp;<a href="#" onclick="ManagerTreeNode('Select');" class="btn btn-app btn-purple btn-xs">
                                            <i class="icon-cloud-upload bigger-160"></i>选择功能</a>--%>
                                </div>
                            </div>
                            <div class="widget-body">
                                <table id="grid-table">
                                </table>
                                <div id="grid-pager">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <input type="hidden" id="hidDeptID" />
    <script type="text/javascript">
        var gridTableID = 'grid-table';
        var gridPagerID = 'grid-pager';
        var gridDelete = false;
        $(document).ready(function () {
            GetModelAuth();
            BindList();
            LoadTree();
        });
        function GetModelAuth() {
            $.ajax({
                type: "get",
                url: "../../Handlers/Handler_UserAuth.ashx?method=GetAuthOperateMax",
                data: "ModuleID=<%=strRequestID %>",
                async: false,
                success: function (txt) {
                    if (txt.indexOf("btnDelete")) {
                        gridDelete = true;
                    }
                    $("#divAuth").html(txt);
                }
            });
        }

        function DeleteGridData() {
            var row = $("#" + gridTableID).jqGrid('getGridParam', 'selarrrow');
            var len = row.length;
            if (row.length > 0) {
                var selectUserID = "";
                for (var i = 0; i < len; i++) {
                    var model = $("#" + gridTableID).jqGrid('getRowData', row[i]);
                    if (selectUserID == "") {
                        selectUserID = model.OperateID;
                    }
                    else {
                        selectUserID += "," + model.OperateID;
                    }
                }
                ShowConfirm(selectUserID, "DeleteModuleOperate");
            }
            else {
                var o = {
                    dialogID: "dialog-confirm",
                    dialogContentID: "dialog-confirm-content",
                    Message: "请先选择要删除的数据"
                };
                showDialog(o);
            }
        }

        function BindList() {
            var url = "../../Handlers/Handler_Module.ashx?method=GetModuleOperateList&ModuleID=" + $("#hidDeptID").val();
            var colNames = ['OperateID', 'ModuleID', '功能名称', '功能值', '样式名称'];
            var colModel = [
				{ name: 'OperateID', index: 'OperateID', width: 60, editable: false, hidden: true, sortable: false },
				{ name: 'ModuleID', index: 'ModuleID', width: 50, editable: false, hidden: true, sortable: false },
				{ name: 'OperateName', index: 'OperateName', width: 40, editable: false, sortable: false },
				{ name: 'OperateValue', index: 'OperateValue', width: 40, editable: false, sortable: false },
                { name: 'CssCss_OP', index: 'CssCss_OP', width: 50, editable: false, sortable: false }
			];
            var dfop =
            {
                GridID: gridTableID,
                GridPagerID: gridPagerID,
                RowNum: 100,
                Url: url,
                ColNames: colNames,
                ColModel: colModel,
                Caption: "功能列表",
                SortName: "OperateValue",
                Height: 180,
                IsShowSearch: false
            };
            showJqGrid(dfop);
            if (gridDelete) {
                $("#" + gridTableID).navButtonAdd("#" + gridPagerID, {
                    caption: "删除",
                    title: "删除",
                    buttonicon: "icon-trash red",
                    onClickButton: function () {
                        DeleteGridData();
                    },
                    position: "last"
                });
            }
        }

        function CBClose_Operate() {
            CBClose();
            Reload();
        }

        function Reload() {
            jQuery("#" + gridTableID).jqGrid('setGridParam', { url: "../../Handlers/Handler_Module.ashx?method=GetModuleOperateList&ModuleID=" + $("#hidDeptID").val(), datatype: "json" }).trigger("reloadGrid");
        }
        function SaveModuleOperate(idList) {
            $.post("../../Handlers/Handler_Module.ashx", { method: "SaveModuleOperate", ModuleID: $("#hidDeptID").val(), OperateID: idList, random: Math.random() },
                function (txt) {
                    var jsonData = $.parseJSON(txt);
                    if (jsonData.State == "true") {
                        showDialogMessage("操作成功");
                        CBClose_Operate();
                    }
                    else {
                        showDialogMessage("操作失败:" + jsonData.Message);
                    }
                }
            );
        }

        function CreateTree() {
            var o = {
                cbiconpath: "../../Images/tree/",
                emptyiconpath: "../../Images/tree/s.gif",
                showcheck: false,
                onnodeclick: function (item) {
                    document.getElementById("txtDeptName").value = setStr(item.text);
                    document.getElementById("hidDeptID").value = item.value;
                    Reload();
                }
            };
            $.ajax({
                type: "GET",
                url: "../../Handlers/Handler_Module.ashx?method=GetModuleTree",
                success: function (msg) {
                    eval("var data =" + msg + ";");
                    o.data = data;
                    $("#tree").treeview(o);
                },
                error: function (msg) {
                    alert("获取数据出现错误:" + msg);
                }
            });
        }

        function LoadTree() {
            window.setTimeout(CreateTree, 100);
        }

        function RestLoad() {
            $("#tree").html("<img src='../../Images/tree/loading.gif' />");
            LoadTree();
        }

        function AlertMessageBoxSelect(file_name) {
            if (file_name == "Refresh") {
                return;
            }
        }
        function setStr(str) {
            return str;
        }

        function Add() {
            var Url = 'Option.aspx?type=Add&DeptGuID=' + $("#hidDeptID").val();
            ShowWindow(Url, "模块管理");
        }

        function Edit() {
            if ($("#hidDeptID").val() == "0") {
                var o = {
                    dialogID: "dialog-confirm",
                    dialogContentID: "dialog-confirm-content",
                    Message: "该节点不能进行修改或删除!"
                };
                showDialog(o);
                return;
            }
            if ($("#hidDeptID").val() == "") {
                var o = {
                    dialogID: "dialog-confirm",
                    dialogContentID: "dialog-confirm-content",
                    Message: "请先选择节点再进行操作!"
                };
                showDialog(o);
                return;
            }
            var Url = 'Option.aspx?type=Edit&DeptGuID=' + $("#hidDeptID").val();
            ShowWindow(Url, "模块管理");
        }

        function Delete() {
            if ($("#hidDeptID").val() == "0") {
                var o = {
                    dialogID: "dialog-confirm",
                    dialogContentID: "dialog-confirm-content",
                    Message: "该节点不能进行修改或删除!"
                };
                showDialog(o);
                return;
            }
            if ($("#hidDeptID").val() == "") {
                var o = {
                    dialogID: "dialog-confirm",
                    dialogContentID: "dialog-confirm-content",
                    Message: "请先选择节点再进行操作!"
                };
                showDialog(o);
                return;
            }
            var varDeptID = $("#hidDeptID").val();
            $.get("../../Handlers/Handler_Module.ashx?method=GetChildrenCount", { DeptID: varDeptID, random: Math.random() },
                    function (txt) {
                        if (txt == "0") {
                            ShowConfirm(varDeptID, "DeleteModule");
                        }
                        else {
                            var o = {
                                dialogID: "dialog-confirm",
                                dialogContentID: "dialog-confirm-content",
                                Message: "选择删除的部门节点含有下级部门,不能进行删除!"
                            };
                            showDialog(o);
                        }
                    }
             );
        }

        function Sort() {
            if ($("#hidDeptID").val() == "") {
                showDialogMessage("请先选择节点再进行操作");
                return;
            }
            var Url = 'Option.aspx?type=Sort&DeptGuID=' + $("#hidDeptID").val();
            ShowWindow(Url, "模块管理");
        }

        function Select() {
            if ($("#hidDeptID").val() == "") {
                var o = {
                    dialogID: "dialog-confirm",
                    dialogContentID: "dialog-confirm-content",
                    Message: "请先选择节点再进行操作!"
                };
                showDialog(o);
                return;
            }
            var Url = 'SelectOperate.aspx?type=Select&DeptGuID=' + $("#hidDeptID").val();
            ShowWindow(Url, "选择功能");
        }

        function ShowConfirm(modelID, TypeName) {
            if (TypeName == "DeleteModule") {
                var o = {
                    DeleteData: { DeptID: modelID, random: Math.random() },
                    DeleteURL: "../../Handlers/Handler_Module.ashx?method=Delete",
                    ReLoad: RestLoad
                };
                showConfirmDialog(o);
            }
            else if (TypeName == "DeleteModuleOperate") {
                var o = {
                    DeleteData: { method: "DeleteModuleOperate", ModuleID: $("#hidDeptID").val(), OperateID: modelID, random: Math.random() },
                    DeleteURL: "../../Handlers/Handler_Module.ashx",
                    ReLoad: Reload
                };
                showConfirmDialog(o);
            }
        }

        function ShowWindow(varUrl, varTitle) {
            var o = {
                title: varTitle,
                href: varUrl
            };
            showColorbox(o);
        }

        function CBClose() {
            $.colorbox.close();
        }

        function CBClose_Load() {
            $.colorbox.close();
            showDialogMessage("操作数据成功");
            RestLoad();
        }
        
    </script>
</asp:Content>
